import Foundation

extension String {
    
    func mp_toDict() -> [String : Any]? {
        guard !self.isEmpty else { return nil }
        guard let dataSelf = self.data(using: .utf8) else {
            return nil
        }
        return dataSelf.mp_toDict()
    }
    
}

extension Data {
    
    func mp_toDict() -> [String : Any]? {
        guard !self.isEmpty else { return nil }
        if let dic = try? JSONSerialization.jsonObject(with: self,
                           options: .mutableContainers) as? [String : Any] {
            return dic
        }
        return nil
    }
    
}

extension UnsafeMutableRawPointer {

    func mp_set(_ value: Any, _ type: Any.Type) {
        return mp_typeProxy(type).mp_set(value, self)
    }
    
    func mp_get(_ type: Any.Type) -> Any? {
        return mp_typeProxy(type).mp_get(self)
    }
    
    func mp_bind<T>(type : T.Type) -> UnsafeMutablePointer<T> {
        return self.assumingMemoryBound(to: type)
    }
    
}
